package com.itheima.comment.controller;

import com.heima.model.common.dtos.CommentDTO;
import com.heima.model.common.dtos.CommentLikeDTO;
import com.heima.model.common.dtos.CommentSaveDTO;
import com.heima.model.common.dtos.ResponseResult;
import com.itheima.comment.server.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/comment")
@Api("用户评论api")
public class CommentController {
    @Autowired
    private CommentService commentService;
    @PostMapping("/save")
    @ApiOperation("评论保存")
    public ResponseResult saveComment(@RequestBody @Validated CommentSaveDTO dto){
        return commentService.saveComment(dto);
    }
    @PostMapping("/load")
    @ApiOperation("评论查询")
    public ResponseResult loadComment(@RequestBody @Validated CommentDTO dto){
        return commentService.findByArticleId(dto);
    }
    @PostMapping("/like")
    @ApiOperation("评论点赞")
    public ResponseResult likeComment(@RequestBody @Validated CommentLikeDTO dto){
        return commentService.like(dto);
    }
}
